<template>
  <a-config-provider :locale="zhCN">
    <router-view />
    <Print v-if="userInfo && userInfo.token" />
    <button @click="deleteUser">删除用户信息</button>
  </a-config-provider>
</template>
<script setup>
import { ref, onMounted } from 'vue'
import { message } from 'ant-design-vue'
import zhCN from 'ant-design-vue/es/locale/zh_CN'
import Print from '@renderer/components/Print.vue'
import { useRouter } from 'vue-router'
const router = useRouter()
const userInfo = ref(null)
// 监听用户信息变化（通过 IPC 或 electronAPI 的回调）
window.api.onUserInfoChanged((newData) => {
  userInfo.value = newData
})

// 监听主进程的消息
window.electron.ipcRenderer.on('change-status', (event, payload) => {
  message.error(payload.msg)
  router.replace('/')
})

const deleteUser = () => {
  window.api.deleteUser()
}
onMounted(async () => {
  userInfo.value = await window.api.getStoreData('user-info')

})
</script>
